<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class IndexController extends AbstractActionController
{

   private function checkLogin() {
      if (! $this->getServiceLocator()
                ->get('AuthService')->hasIdentity()){
         return $this->redirect()->toRoute('login');
      }
   }

   public function indexAction()
   {

      $this->checkLogin();

      $authservice = $this->getServiceLocator()->get('AuthService');
      $username = $authservice->getIdentity();
      $usuario = $this->getServiceLocator()->get('Usuarios\Model\UsuarioTable')->getUsuarioByUserName($username);
      $roleservice = $this->getServiceLocator()->get('RoleService');

      return array(
         'user_id' => $usuario->id,
         'authservice' => $authservice,
         'roleservice' => $roleservice
      );
      //return new ViewModel();

   }
}
